﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Citiport.Util.Language;

public partial class ct_s_new_intro : System.Web.UI.Page
{
    int no;

    ctpDataContext db;
    ct_s_profile cts;

    protected void Page_Load(object sender, EventArgs e)
    {

        
        no = int.Parse(Request["no"]);
        ctp_lib.check_login(this.Page, "city_s_new_intro.aspx?no=" + no.ToString());


        db = new ctpDataContext();
         cts = db.ct_s_profiles.Single(p => p.valid == true && p.no == no && p.language_no == (int)Session["now_user_lang_no"]);


        if (!this.IsPostBack)
        {

            this.HyperLink3.Text = cts.title;
            this.HyperLink3.NavigateUrl = "city_s.aspx?no=" + no.ToString().Trim();
            this.HyperLink2.Text = cts.ct_profile.title.Trim();
            this.HyperLink2.NavigateUrl = "city.aspx?no=" + cts.ct_no;

        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        ctpDataContext db = new ctpDataContext();
        ct_s_intro i = new ct_s_intro();

        i.create_user_no = (int)Session["userno"];
        i.ct_s_no = no;
        i.ct_no = cts.ct_no;
        string tempno = DateTime.Now.Minute.ToString() + "_" + DateTime.Now.Second.ToString();

        i.addtime = DateTime.Now;
        i.intro = this.TextBox1.Text;



        //i.intro = "本篇文章原文為英文,並由citiport自動翻譯.<a href='javascript://' onclick=\"mytr"+tempno+".style.display='inline'\">檢視原文</a><hr>";
        //i.intro += "<div id='mytr"+tempno+"' style='display:none'>" + this.TextBox1.Text + "<hr></div>";
        
        //i.intro += TranslateUtil.GetTranslatedText(this.TextBox1.Text, LangPair.EnglishToChineseSimplified);
        //i.intro += "<p><a href=''>修改翻譯</a>";




        i.language_no = (int)Session["now_user_lang_no"];

        db.ct_s_intros.InsertOnSubmit(i);
        db.SubmitChanges();

        DatabaseUtil my_util = new DatabaseUtil();
        //Hashtable ht = my_util.getLangTable();


        var data = from p in db.ct_s_intros
                   where p.create_user_no == (int)Session["userno"]
                   orderby p.addtime descending
                   select p;
        i = data.First();
       
        my_util.writeTranslatedTxt((int)DatabaseUtil.fromTables.intro_intro, i.no, this.TextBox1.Text, "en");



        ctp_lib.add_user_city((int)Session["userno"], (int)i.ct_no);


        Response.Redirect("city_s.aspx?no="+no.ToString());
    }
}
